var vo={};
$(function(){
	var openWindow=window.document;
	var searchHeight=$("#divform").height();
	$("#listUpload").height($(openWindow).height()-$(openWindow).height()*0.05-searchHeight-10);
	//动态设置改变操作列宽度
	var fcol=opt.split('</a>');
	var contrlColumn=0;
	if(fcol.length>0){
		contrlColumn=(fcol.length-1)*fcolMaxWidth;
	}
	$("#listUpload").datagrid({
					url:'/uploaddata/getUpload',
					title:'未上传数据列表',
					method:'get',
					pagination:true,
					pageList: [15,30,100,500],
					loadMsg:'加载中......',
					toolbar:'#tb',
					columns:[[
					         {field:'ck',checkbox:true},
							 {field:'did' ,align:'center',title:'操作',width:contrlColumn,formatter: function(value, row, index){
								 var re=new RegExp("{param}","g");
								 var ref=opt.replace(re,value);
								 return ref;
							 }},
							 {field:'idcard',title:'身份证号',width:120,align:'center'},
					         {field:'username',title:'用户名称',width:80,align:'center'},
					         {field:'sex',title:'性别',width:40,align:'center'},
					         {field:'huiyuanziliao_nianling',title:'年龄',width:40,align:'center'},
					         {field:'birthdate',title:'出生日期',width:80,sortable:true,align:'center',formatter:function(value,row,index){
					        	 if(value==''){
					        		 return '';
					        	 }
					        	 var datetime=Common.formatterDate(value);
					        	 return datetime;
					         }},
					         {field:'address',title:'住址',width:250,align:'center'},
					         {field:'phone',title:'电话',width:100,sortable:true,align:'center'},
					         {field:'huiyuanziliao_jianchariqi',title:'检查日期',width:80,align:'center'},
					         {field:'huiyuanziliao_jianchashijian',title:'检查时间',width:80,align:'center'},
					     ]]
				});
	$("#serbutton").click(function(){
		vo.idcard=$("#idcard").val();
		vo.username=$("#username").val();
		vo.begintime=$('#beginTime').datebox('getValue');
		vo.endtime=$('#endTime').datebox('getValue');
		$("#listUpload").datagrid('load',vo);
	});
	$("#listUpload").datagrid({
		toolbar: '#tb'
	});
	//绑定回车事件
	$(document).keydown(function(event){ 
		if(event.keyCode==13){
			$("#serbutton").click(); 
		}
	});
	$('#beginTime').datebox({});  
	$('#endTime').datebox({}); 
	//如果操作项为空隐藏操作列
	if(opt==''){
		$("#listUpload").datagrid('hideColumn','did');
	}
});
/**
 * 上传
 */
function upload(id){
	$.messager.confirm('作废','您确定要将数据上传到app吗？',function(data){
		if(data){
			window.parent.showloading();
			$.ajax({
				type:'get',
				url: '/uploaddata/upload',
				data:{did:id},
				success:function(data){
					window.parent.hideloading();
					if(data.code==200){
						$.messager.alert("上传","上传成功",'info',function(){
							$("#listUpload").datagrid('load',vo);
						});
					}
					else{
						$.messager.alert("上传","上传失败："+data.msg,'error');
						$("#listUpload").datagrid('load',vo);
					}
				},
				error:function(data){
					window.parent.hideloading();
					$.messager.alert("上传","上传失败：",'error');
				}
			});
		}
	})
}
/**
 * 批量上传
 */
function betchupload(){
	var rows=$("#listUpload").datagrid('getSelections');
	if(rows.length<=0){
		$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	$.messager.confirm('作废','您确定要上传选中的数据到APP吗？',function(data){
		if(data){
			window.parent.showloading();
			var ids='';
			for(var i=0;i<rows.length;i++){
				ids+=rows[i].did+',';
			}
			$.ajax({
				type:'get',
				url: '/uploaddata/betchUpload',
				data:{ids:ids},
				success:function(data){
					window.parent.hideloading();
					if(data.code==200){
						$.messager.alert("上传","上传成功",'info',function(){
							$("#listUpload").datagrid('load',vo);
						});
					}
					else{
						$.messager.alert("失败","上传失败："+data.msg,'error');
					}
				},
				error:function(data){
					window.parent.hideloading();
					$.messager.alert("失败","上传失败：",'error');
				}
			});
		}
	})
}
